package com.rpcfx.api;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * @ProjectName: learning
 * @Package: com.rpcfx.api
 * @ClassName: ServiceLoader
 * @Description:
 * @Date: 2021/11/11 11:46 下午
 * @Version: 1.0
 */
public class ServiceLoader {


    public static <T> List<T> load(Class<T> claszz) {
        List<T> result = new ArrayList<>();
        java.util.ServiceLoader<T> serviceLoader = java.util.ServiceLoader.load(claszz, Thread.currentThread().getContextClassLoader());
        Iterator<T> iterator = serviceLoader.iterator();
        while (iterator.hasNext()) {
            result.add(iterator.next());
        }
        return result;
    }
}
